package cn.dnui_zzh807.dnuifood_16110100807.SomethingElse;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import java.util.List;

import cn.dnui_zzh807.dnuifood_16110100807.R;
import cn.dnui_zzh807.dnuifood_16110100807.adapter.CommentAdapter;
import cn.dnui_zzh807.dnuifood_16110100807.bean.CommentInfo;
import cn.dnui_zzh807.dnuifood_16110100807.listener.OnRetrofitListener;
import cn.dnui_zzh807.dnuifood_16110100807.model.UserModel;

public class User_Comments extends AppCompatActivity implements OnRetrofitListener<List<CommentInfo>> {
  private String user_id;
  private RecyclerView recyclerView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user__comments);
        user_id=getIntent().getStringExtra("user_id");
        recyclerView  = (RecyclerView)findViewById(R.id.user_comment_list);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        initData();
    }

    private void initData(){
        UserModel userModel = new UserModel();
        userModel.getAllCommentsByUser(user_id,this);
    }
    @Override
    public void onSuccess(List<CommentInfo> comments, int flag) {
     CommentAdapter userCommentAdapter = new CommentAdapter(this,comments);
        recyclerView.setAdapter(userCommentAdapter);
        Toast.makeText(User_Comments.this,"网络成功",Toast.LENGTH_SHORT).show();
    }

    @Override
    public void onFail() {
        Toast.makeText(User_Comments.this,"网络错误",Toast.LENGTH_SHORT).show();
    }
}
